import { computed, ref } from 'vue'
import { defineStore } from 'pinia'
import { RouteRecordRaw } from 'vue-router'
export const useRouterList = defineStore('routerList', () => {
  const defaultRouter = ref<RouteRecordRaw[] | []>([])
  const authRouter = ref<RouteRecordRaw[] | []>([])
  function setAuthRouter(list: Array<RouteRecordRaw> | []) {
    authRouter.value = list
  }
  function setDefaultRouter(list: Array<RouteRecordRaw> | []) {
    defaultRouter.value = list
  }
  const cachePageList = computed(() => {
    const nameList: string[] = []
    authRouter.value.forEach((val) => {
      if (val.children && val.children?.length > 0)
        val.children?.forEach((item) => {
          item.meta?.cache !== false && nameList.push(item.name as string)
        })
    })
    return nameList
  })
  return { authRouter, setAuthRouter, defaultRouter, setDefaultRouter, cachePageList }
})
